package com.plant.controller;

import com.plant.common.result.Result;
import com.plant.common.result.ResultCodeEnum;
import com.plant.entity.Classify;
import com.plant.entity.GoodsOrder;
import com.plant.entity.Parameter;
import com.plant.service.ClassifyService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (Classify)表控制层
 *
 * @author makejava
 * @since 2024-08-25 19:00:33
 */
@Slf4j
@RestController
@RequestMapping("/classify")
public class ClassifyController {
    /**
     * 服务对象
     */
    @Resource
    private ClassifyService classifyService;


    @PostMapping("/classList")
    public Result classList() {
        List<Classify> classifies = classifyService.classList();
        if (classifies == null && classifies.isEmpty()) {
            return Result.fail(classifies);
        }
        return Result.ok(classifies);
    }

    @GetMapping("/parameterList/{id}")
    public Result parameterList(@PathVariable Integer id) {
        List<Parameter> parameters = classifyService.parameterList(id);
        return Result.ok(parameters);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/classById/{id}")
    public ResponseEntity<Classify> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.classifyService.queryById(id));
    }

    @PostMapping("/cartAdd")
    public Result cartAdd(@RequestBody Parameter parameter) {
        return Result.build(classifyService.cartAdd(parameter), ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/cartList/{uid}")
    public Result cartList(@PathVariable Integer uid) {
        return Result.ok(classifyService.cartList(uid));
    }

    @PostMapping("/orderAdd")
    public Result orderAdd(@RequestBody GoodsOrder goodsOrder) {
        try {

            return Result.ok(classifyService.orderAdd(goodsOrder));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    @PostMapping("/orderInstrel")
    public Result orderInstrel(@RequestBody GoodsOrder goodsOrder) {
        try {

            return Result.ok(classifyService.orderInstrel(goodsOrder));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

        @PostMapping("/UpStatus/{orderId}")
    public Result UpStatus(@PathVariable String orderId) {
        try {

            return Result.ok(classifyService.UpStatus(orderId));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @PostMapping("/deRedis/{orderId}")
    public Result deRedis(@PathVariable Long orderId) {
        return Result.ok(classifyService.deRedis(orderId));
    }

    @PostMapping("/orderList/{orderId}")
    public Result orderList(@PathVariable String orderId) {

        return Result.ok(classifyService.orderList(orderId));
    }

    @PostMapping("/orderList1/{orderId}")
    public Result orderList1(@PathVariable String orderId) {

        return Result.ok(classifyService.orderList1(orderId));
    }


}

